<?php
if ($ticket_parent!=1) {
	header('Location: class_manager.php');
	exit;
}


if(isset($_POST["add_class_form_nr_dates"]) && intval($_POST["add_class_form_nr_dates"])>0 && intval($_POST["add_class_form_nr_dates"])<=5){
	$nr_dates = intval($_POST["add_class_form_nr_dates"]);
}
else{
	$nr_dates = 2;
}

?>
<link rel="stylesheet" href="styles/datepicker.css" media="screen" />
<script type="text/javascript" src="scripts/datepicker.js"></script>


<div class="form">
<h2 class="spaced">Add Class</h2>
<form name="add_class_form"
	action="class_manager.php?page=admin&admin_page=add_class"
	method="post">
<table class="form">
	<tr>
		<td align="right">Module*:</td>
		<td align="left" colspan="3">
			<select style="width:450px;margin:0" name="add_class_form_module" >
				<?php
				$result = mysql_query("SELECT pkey, long_name, short_name FROM modules ORDER BY long_name ASC", $class_manager_db) or die(mysql_error($class_manager_db));
				while ($line = mysql_fetch_array($result,MYSQL_ASSOC)) {
					echo '<option value="'. $line["pkey"] .'"';
					if(isset($_POST["add_class_form_module"]) && $_POST["add_class_form_module"]==$line["pkey"])
						echo 'selected';
					echo '>'. htmlspecialchars(stripslashes($line["long_name"])) .' ('.htmlspecialchars(stripslashes($line["short_name"])).')</option>';
				}
				?>
			</select>
		</td>
	</tr>
	<tr>
		<td align="right">Fee*:</td>
		<td align="left"><input type="text" style="width: 100px"
			name="add_class_form_fee" <?php if(isset($_POST["add_class_form_fee"])) echo 'value="'.htmlspecialchars($_POST["add_class_form_fee"]).'"';?>></td>
		<td align="right">Capacity (leave blank for unlimited):</td>
		<td align="left"><input type="text" style="width: 100px"
			name="add_class_form_capacity" <?php if(isset($_POST["add_class_form_capacity"])) echo 'value="'.htmlspecialchars($_POST["add_class_form_capacity"]).'"';?>></td>
	</tr>
	<tr>
		<td valign="top" align="right">Comments:</td>
		<td align="left" colspan="3"><textarea rows="10" style="width: 450px"
			name="add_class_form_comments"><?php if(isset($_POST["add_class_form_comments"])) echo htmlspecialchars($_POST["add_class_form_comments"]);?></textarea></td>
	</tr>
	<tr>
		<td colspan="4"><hr></td>
	</tr>
	<tr>
		<td colspan="4"><h3>Registration Begin Date and Time</h3>&nbsp;&nbsp;&nbsp;(leave blank for none)</td>
	</tr>
	<tr>
		<td align="right">Date (dd.mm.yyyy):</td>
		<td align="left"><input type="text" style="width: 100px"
			name="add_class_form_reg_start_date"
			<?php if(isset($_POST["add_class_form_reg_start_date"])) echo 'value="'.htmlspecialchars($_POST["add_class_form_reg_start_date"]).'"';?>>&nbsp;<a
			onclick="displayDatePicker('add_class_form_reg_start_date',false,'dmy','.')" class="clickable"><img
				src="images/cal.gif" alt="Pick a date..."
				style="width: 16px; height: 16px; border: 0px;"> </a>
		</td>
		<td align="right">Time (HH:MM):</td>
		<td align="left"><input type="text" style="width: 100px"
			name="add_class_form_reg_start_time"
			<?php if(isset($_POST["add_class_form_reg_start_time"])) echo 'value="'.htmlspecialchars($_POST["add_class_form_reg_start_time"]).'"';?>>
		</td>
	</tr>
	<tr>
		<td colspan="4"><hr></td>
	</tr>
	<tr>
		<td colspan="4"><h3>Class Sessions</h3></td>
	</tr>
	<tr>
		<td align="right">Number of Class Sessions*:</td>
		<td align="left" valign="bottom" colspan="3">
			<select style="width:40px;margin:0" name="add_class_form_nr_dates"  onchange="document.add_class_form.submit();">
				<option value="1" <?php if($nr_dates == 1) echo("selected");?>>1</option>
				<option value="2" <?php if($nr_dates == 2) echo("selected");?>>2</option>
				<option value="3" <?php if($nr_dates == 3) echo("selected");?>>3</option>
				<option value="4" <?php if($nr_dates == 4) echo("selected");?>>4</option>
				<option value="5" <?php if($nr_dates == 5) echo("selected");?>>5</option>
			</select>
		</td>
	</tr>	
	<tr>
		<td colspan="4"><hr></td>
	</tr>
<?php 

for ($i=0;$i<$nr_dates;$i++){
	

?>
	<tr>
		<td colspan="4"><h4>Session <?php echo $i+1;?> Date and Time</h4></td>
	</tr>
	<tr>
		<td align="right">Date (dd.mm.yyyy)*:</td>
		<td align="left"><input type="text" style="width: 100px"
			name="add_class_form_start_date_<?php echo $i;?>" 
			<?php if(isset($_POST["add_class_form_start_date_".$i])) 
				echo 'value="'.htmlspecialchars($_POST["add_class_form_start_date_".$i]).'"';?>>&nbsp;<a
				onclick="displayDatePicker('add_class_form_start_date_<?php echo $i;?>',false,'dmy','.')" class="clickable"><img
				src="images/cal.gif" alt="Pick a date..."
				style="width: 16px; height: 16px; border: 0px;"> </a>
		</td>
		<td align="right">Time (HH:MM)*:</td>
		<td align="left"><input type="text" style="width: 100px"
			name="add_class_form_start_time_<?php echo $i;?>"
			<?php if(isset($_POST["add_class_form_start_time_".$i])) 
				echo 'value="'.htmlspecialchars($_POST["add_class_form_start_time_".$i]).'"';?>>
		</td>
	</tr>
	<tr>
		<td align="right">Duration (hours)*:</td>
		<td align="left" colspan="3"><input type="text" style="width: 100px"
			name="add_class_form_duration_<?php echo $i;?>"
			<?php if(isset($_POST["add_class_form_duration_".$i])) 
				echo 'value="'.htmlspecialchars($_POST["add_class_form_duration_".$i]).'"';?>>
		</td>
	</tr>
	<tr>
		<td valign="top" align="right">Comments:</td>
		<td align="left" colspan="3"><textarea rows="10" style="width: 450px"
			name="add_class_form_session_comments_<?php echo $i;?>"><?php 
			if(isset($_POST["add_class_form_session_comments_".$i])) 
				echo htmlspecialchars($_POST["add_class_form_session_comments_".$i]);?></textarea>
		</td>
	</tr>
	<tr>
		<td colspan="4"><hr></td>
	</tr>
<?php 
}
?>	
	<tr>
		<td  colspan="4"><input type="submit" name="add_class_form_submit" value="Add Class" />
		</td>
	</tr>
	<tr>
		<td colspan="4">* required fields</td>
	</tr>
</table>
</form>
</div>